package com.example.work;

import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;

import java.util.ArrayList;
import java.util.List;

public class BlankFragment extends Fragment {

    private int savedInstanceState = 0;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        View view = inflater.inflate(R.layout.fragment_blank, container, false);

        // 初始化数据
        int type = -1;
        List<BlankBean> name = new ArrayList<>();
        Bundle bundle = getArguments();
        if (bundle != null) {
            type = bundle.getInt("type", -1); // 提供默认值 -1
            Log.d("BlankFragment", "Received type: " + type);
        }

        if (type == 0) {
            name.add(new BlankBean("《蔬菜主义》1人套餐", "月销26 好评度70%", "￥44", R.drawable.dish_1));
            name.add(new BlankBean("二人经典套餐", "月销12 好评度50%", "￥132", R.drawable.dish_2));
            name.add(new BlankBean("三人经典套餐", "月销4 好评度40%", "￥180", R.drawable.dish_3));
        } else if (type == 1) {
            name.add(new BlankBean("爆款*肥牛鱼豆腐骨肉相连三荤五素一份米饭", "月销520 好评度80%", "￥23", R.drawable.signature_dish_1));
            name.add(new BlankBean("豪华双人套餐", "月销184 好评度68%", "￥41", R.drawable.signature_dish_2));
            name.add(new BlankBean("【热销】双人套餐（含两份米饭）", "月销114 好评度60%", "￥32", R.drawable.signature_dish_3));
        }
        for (int i = 0; i < name.size(); i++){
            Log.d("BlankFragment", "name: " + name.get(i).getTitle());
            Log.d("BlankFragment", "name: " + name.get(i).getAppraise());
            Log.d("BlankFragment", "name: " + name.get(i).getPrice());
            Log.d("BlankFragment", "name: " + name.get(i).getImageId());


            // 加入到fragment中
            ImageView imageView = view.findViewById(R.id.Img_tv);
            imageView.setImageResource(name.get(i).getImageId());
            TextView textView = view.findViewById(R.id.title_tv);
            textView.setText(name.get(i).getTitle());
            TextView textView1 = view.findViewById(R.id.price_tv);
            textView1.setText(name.get(i).getAppraise());
            TextView textView2 = view.findViewById(R.id.sold_tv);
            textView2.setText(name.get(i).getPrice());

        }


        return view;
    }
}